from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField


# Create your models here.

# python manage.py makemigrations
# 如果修改过model，需要先执行这个命令更新数据，再使用下一个命令
# python manage.py migrate
# 自动生成相关数据库表
class Category(models.Model):
    # 后台显示的名称设置
    class Meta:
        verbose_name = "商品"  # 非复数显示名称
        verbose_name_plural = "商品列表"  # 复数显示名称

    id = models.BigAutoField(verbose_name='id', primary_key=True)
    is_delete = models.BooleanField(verbose_name='是否删除', default='false', blank=True)
    name = models.CharField(verbose_name='商品分类', max_length=20, null=False, unique=True)
    description = models.CharField(verbose_name='分类描述', max_length=1000, null=False, blank=True)
    detail = RichTextUploadingField(verbose_name="详情", null=True)
    src = models.ImageField(verbose_name='分类图片', upload_to='static/up;oad/category', null=True, blank=True)
    pid = models.ForeignKey('self', verbose_name='上级分类', related_name='category_category',
                            on_delete=models.SET_NULL, default=None, null=True, blank=True)

    def __str__(self):
        return self.name
